#include <stdio.h>
#include <time.h>
#include<sys/time.h>
#include<stdlib.h>
#include<cblas.h>
int main()
{
	int i,j,m,n,a,b,h,sum;
	double time1,time2;
    double speedup;
	struct timeval start;
	struct timeval end;
	sum=0;
	int e;
	for(m=16;m<=4096;)
	{
                 double M[m][m],N[m][m],K[m][m];
		i=j=n=m;
		for(a = 0 ; a < m ; a++){
			for(b = 0 ; b < n ; b++){
				M[a][b]=N[a][b]=3.2;
			}
		} 	
		gettimeofday(&start,NULL);

		if(j==m)
		{
			for(h=0;h<i;h++)
			{
				for(b=0;b<n;b++)
				{
					for(a=0;a<j;a++)
					{
						sum=sum + M[h][a]*N[a][b];
						if(a==j-1)
						{
							//printf("%-3d",sum);
							K[h][b]=sum;
						}
					}
					a=1;
					sum=0;			
				}		
				//printf("\n");
			}
		}
		gettimeofday(&end,NULL);
		time1=1000000*(end.tv_sec-start.tv_sec)+(end.tv_usec-start.tv_usec);
   time1/=1000000;
		e=m*m;
		double A[e],B[e],C[e];
		for(i=0;i<e;i++)
		{
			A[i]=B[i]=C[i]=3.2;
		}
		gettimeofday(&start,NULL);
		cblas_dgemm(CblasColMajor,CblasNoTrans,CblasTrans,m,m,m,1,A,m,B,m,0,C,m);
		gettimeofday(&end,NULL);
		time2=1000000*(end.tv_sec-start.tv_sec)+(end.tv_usec-start.tv_usec);
    time2/=1000000;
		speedup =(time1/10000)/(time2/10000);
		printf("常规矩阵乘法所需时间：%f BLAS用时：%f,加速比为：%f\n",time1,time2,speedup);
		m=m+32;
	}
	return 0;
}

